package com.dw.etl.core.controller;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.dw.etl.core.bean.vo.LayMsg;
import com.dw.etl.core.bean.vo.Msg;
import com.dw.etl.core.bean.model.SysUsers;
import com.dw.etl.core.api.CoreAuthorizationService;
import com.dw.etl.core.api.UserService;
import com.dw.etl.core.utils.Ognlutis;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author GuoPeng
 * @Title: CoreAuthorizationController
 * @Description: 权限核心控制器
 * @date 2019/5/8 10:47
 */
@Controller
@CrossOrigin(origins = "*", maxAge = 3600)
public class CoreAuthorizationController {


    @Resource
    private CoreAuthorizationService coreAuthorizationService;

    @Resource
    private UserService userService;

    /**
     * 用户登录授权
     * param username
     * param password
     * param yzm
     *
     * @return
     */
    @RequestMapping("/authorization")
    @ResponseBody
    public Msg authorization(@RequestBody String json) {
        Gson gson = new Gson();
        Map<String, String> data = (Map) gson.fromJson(json, new TypeToken<Map<String, String>>() {
        }.getRawType());
        return coreAuthorizationService.authorization(data.get("username"), data.get("password"), data.get("yzm"));
    }

    /**
     * 获取验证码
     * @param email
     * @return
     */
    @RequestMapping("/getYzm")
    @ResponseBody
    public Msg getYzm(String email) {
        return coreAuthorizationService.getEmailyzm(email);
    }


    /**
     * 登录验证
     * @param LoginToken
     * @return
     */
    @RequestMapping("/autLoginToken")
    @ResponseBody
    public Msg autLoginToken(String LoginToken) {
        return coreAuthorizationService.autLoginToken(LoginToken);
    }



    @RequestMapping("/getRoleslist")
    @ResponseBody
    public LayMsg getRoleslist(String LoginKey, Integer page, Integer limit) {
        return userService.getuserList( page, limit);
    }



}
